package cn.ztydata.teachingsystem.heaven.dao.redis;

import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Repository;

import java.util.Set;

/**
 * 知识点->习题 redis类
 * Created by chenxin on 2014/12/8.
 */
@Repository
public class KpExerciseDao extends BaseRedisDao {
    /**
     * 判断知识点是否被用
     * @param kpId 知识点ID
     * @return boolean
     *
     * @author cx
     * @since 2015-02-04
     */
    public boolean isUsed(final long kpId) {
        //获取Set操作
        SetOperations<String, Long> setOperations = redisTemplate.opsForSet();

        logger.debug("return 引用知识点的习题ID");
        //获取Set大小
        return setOperations.size(KeyUtils.generateKey(ExerciseKpDao.KP_EXERCISE, kpId)) > 0;
    }

    /**
     * 获取知识点关联的习题编号
     *
     * @author fanruiping
     * @since 2015/03/27
     */
    public Set<Long> getExerciseIds(final long kpId) {
        SetOperations<String, Long> setOperations = redisTemplate.opsForSet();

        logger.debug("获取知识点关联的习题编号");
        return setOperations.members(KeyUtils.generateKey(ExerciseKpDao.KP_EXERCISE,kpId));
    }
}
